/*
 * Copyright 2010, 2011 Matt Oliveri
 *
 * This file is part of JConfigGen
 *
 * JConfigGen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JConfigGen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JConfigGen.  If not, see <http://www.gnu.org/licenses/>.
 */

package atma.jconfiggen;

import java.io.PrintStream;

/** Refer to the result of a side-effect-free Java expression.
 * <p>
 * This expression type is like {@link Code} except it assumes the specified Java expression does not have side-effects.
 * A surprisingly large variety of Java expressions have side effects.
 * For example, any method call has side effects (no matter which method) because it might throw a {@link StackOverflowError}.
 * It is recommended that you only use {@code NoFX} for string literals, primitive type literals, and local variables (i.e. ids).
 * If for some reason you do have side effects in a {@code NoFX} expression, just beware that these effects might be repeated, skipped, or performed in the wrong order.
 * The benefit from all this is that the result of a {@code NoFX} will never be stored in a temporary variable. Woo!
 * </p>
 * <p>
 * A {@code NoFX} cannot be given an id or result type.
 * If you need to specify either of those, use a {@link Code}.
 * </p>
 */
public final class NoFX extends Expr
{
	private final int line;
	private final String code;

	/** Construct a {@code NoFX}.
	 * @param l The line number this expression was on.
	 * @param c The Java code to evaluate.
	 */
	public NoFX(int l,String c) {line = l;code = c;}

	void printType(PrintStream out) throws InvalidConfigException {needType(line,code);}
	boolean hasStats() {return false;}
	void discard() {}
	void statize() {}
	boolean useId(String i) {return false;}
	void printStats(PrintStream out,int tabs) {}
	void printExpr(PrintStream out) {out.print(code);}
}
